package org.example.finalsecurities.utils;

/**
 * @author 戴诚棋
 * @version 1.0
 * 工具类 通过正则表达式将unicode编码转成 “ > "
 */
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class UnicodeDecoder {
    private static final Pattern UNICODE_PATTERN = Pattern.compile("\\\\u([0-9a-fA-F]{4})");

    public static String decode(String str) {
        Matcher matcher = UNICODE_PATTERN.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            String hex = matcher.group(1);
            int codePoint = Integer.parseInt(hex, 16);
            matcher.appendReplacement(sb, String.valueOf((char) codePoint));
        }
        return matcher.appendTail(sb).toString();
    }
}

